package asia.doing.controller.front;
import asia.doing.common.Result;
import asia.doing.entity.Category;
import asia.doing.entity.Tag;
import asia.doing.service.front.TagService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "标签管理" ,description = "页面展示管理系统文章相关接口")
@RestController(value = "frontTagController")
@RequestMapping("/v1/front/tag")
public class TagController {
    @Resource
    private TagService tagService;

    @ApiOperation(value = "id查询标签")
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id) {
        Tag tag = new Tag();
        tag.setId(id);
        List<Tag> tags = tagService.selectTag(tag);
        return Result.success(tags.get(0));
    }

    /**
     * 分页查询
     */
    @ApiOperation(value = "标签分页")
    @GetMapping
    public Result selectPage(Tag tag,
                             @RequestParam(required = false) Integer pageNum,
                             @RequestParam(required = false) Integer pageSize) {
        if (pageNum == null || pageSize == null) {
            List<Tag> tags = tagService.selectTag(tag);
            return Result.success(tags);
        }else{
            PageInfo<Tag> page = tagService.selectPage(tag, pageNum, pageSize);
            return Result.success(page);
        }
    }
}
